package ${thisPackage}.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import ${thisPackage}.domain.*;
import ${thisPackage}.service.*;

/**
 * auto generate by wencst
 * @author ${author}
 * @since ${.now}
 */
 
<#list columns as col>
	<#if col.primaryKey>
		<#assign  primaryKeyType=col.javaType/>
	<#break>
	</#if>
</#list>
@Controller
@RequestMapping("${javaBeanName}")
public class ${javaBeanName}Controller{

	@Autowired
	${javaBeanName}Service myService;
	
	@RequestMapping("test")
	@ResponseBody
	public Object test(){
		return "success";
	}

	@RequestMapping("listAll")
	@ResponseBody
	public List<${javaBeanName}> listAll(){
		List<${javaBeanName}> list = myService.listAll();
		return list;
	}
	

	@RequestMapping("add")
	@ResponseBody
	public Object add(${javaBeanName} bean){
		int count = myService.save(bean);
		return count;
	}

	@RequestMapping("update")
	@ResponseBody
	public Object update(${javaBeanName} bean){
		int count = myService.update(bean);
		return count;
	}

	@RequestMapping("delete")
	@ResponseBody
	public Object delete(@RequestParam ${primaryKeyType} id){
		int count = myService.delete(id);
		return count;
	}

	@RequestMapping("detail")
	@ResponseBody
	public Object detail(@RequestParam ${primaryKeyType} id){
		ProductPlan detail = myService.detail(id);
		return detail;
	}

	@RequestMapping("getByPage")
	@ResponseBody
	public Map<String, Object> getByPage(@RequestParam int page, @RequestParam int limit){
		Pageable pa = PageRequest.of(page-1, limit);
		Page<${javaBeanName}> bcl = myService.listByPage(pa);
		Map<String,Object> res = new HashMap<String,Object>();
		res.put("data", bcl.getContent());
		res.put("count", bcl.getTotalElements());
		res.put("msg","no messages");
		res.put("code", 0);
		return res;
	}
	@RequestMapping("{page}") 
	public String toPage(@PathVariable("page") String page) {
		return "/${javaBeanName}/"+page;
	}
}